home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / AMarquee / examples / amarqueehost.rexx < prev    next >
OS/2 REXX Batch file  |  1998-06-24  |  6KB  |  166 lines

  1. /*************************************************
  2.  
  3.    AMarqueeHost.rexx
  4.  
  5.    Author: Jeremy Friesner (jaf@chem.ucsd.edu)
  6.    
  7.    An ARexx implementation of AMarqueeHost.c.  Works pretty much
  8.    the same as the C version does!  Requires amarquee.library
  9.    v46 or higher.
  10.  
  11.    Usage:  rx AMarqueeHost.rexx [serverName] [portNumber] [logName]
  12.    
  13. ***************************************************/
  14.  
  15. parse arg hostnames lognames portNum .
  16.  
  17. if (serverName == '?') then do
  18.   say "Usage: rx AMarqueeHost.rexx [hostnames] [lognames] [port]"
  19.   say "       (defaults args are #? #? 0)"
  20.   exit
  21.   end
  22.   
  23. if (length(hostnames) = 0) then hostnames = '#?'
  24. if (length(lognames)  = 0) then lognames  = '#?'
  25. if (length(portNum)   = 0) then portNum   = 0
  26.  
  27. /* We need to trap all the different ways the script could exit,
  28.    so that we can be sure any allocated QSessions or QMessages are
  29.    freed properly */
  30. signal on error
  31. signal on syntax
  32. signal on halt
  33. signal on break_c
  34. signal on break_f
  35.  
  36. /* Used to track allocated QSession and QMessage */
  37. session = 0
  38. message = 0
  39.  
  40. /* Note the offset MUST be -204, and not -30 like in many other
  41.    libraries!  Note also that we require amarquee.library v46 or higher */
  42. check = addlib('amarquee.library', 0, -204, 46)
  43.  
  44. session = QNewHostSession(hostnames, portNum, lognames)
  45. if (session > 0) then 
  46. do
  47.   portNum = word(session, 2)
  48.   say "Waiting for connections from /" || hostnames || "/" || lognames || " on port " || portNum || "."
  49.   say "(Try running:  AMarqueeDebug localhost test " || portNum || ")"
  50.   say ""
  51.   say "Commands are:"
  52.   say ""
  53.   say "a wildhostpath   Access control (default is /#?/#?)"
  54.   say "A wildhostpath   Access control for incoming messages (default in no access)"
  55.   say "m hosts=arg2     Send an active message to hosts"
  56.   say "M hosts=string   Send an system message to hosts"
  57.   say "s path=arg2      Set arg2 node value"
  58.   say "S path=arg2      Stream arg2 node value"
  59.   say "r path=newlabel  Rename arg2 node"
  60.   say "D debugstring    Send debug string"
  61.   say "g wildpath       Get a node or nodes"
  62.   say "c wildpath       Subscribe to a node or nodes"
  63.   say "C wildpath       Get&Subscribe to a node or nodes"
  64.   say "k opID           Klear subscriptions (by id or 0 for all)"
  65.   say "d wildpath       Delete a node or nodes"
  66.   say "i                Request info packet"
  67.   say "p                Request ping packet"
  68.   say "v #              Request new privileges (by code bitchord)"
  69.   say "w #              Release existing privileges (by code bitchord)"
  70.   say "! hosts          Kill other clients (requires KILLCLIENTS privilege!)"
  71.   say "$ param=string   Set a parameter with QSetParam()"
  72.   say "? param          Get a parameter by name"
  73.   say "<enter>          Send accumulated transactions (GO!!)"
  74.   say ""
  75.   say "Press CTRL-F to enter commands, or CTRL-C to quit"
  76.  
  77. MainLoop:
  78.   do forever=1
  79.     /* This will block until we get a signal (e.g. CTRL-C) or a QMessage
  80.        arrives over our connection. */
  81.     message = GetNextQMessage(session)
  82.     
  83.     if (message > 0) then do
  84.         say "QMessage received---------"
  85.         say "Status:       " || GetQMessageField(message, 'Status') || " (" || QErrorName(GetQMessageField(message, 'Status')) || ")"
  86.         say "Error Line:   " || GetQMessageField(message, 'ErrorLine')
  87.         say "Message ID:   " || GetQMessageField(message, 'ID')
  88.         say "Path:         " || GetQMessageField(message, 'Path')
  89.         say "Data:         " || GetQMessageField(message, 'Data')
  90.         say "DataLen:      " || GetQMessageField(message, 'DataLen')
  91.         say "ActualLen:    " || GetQMessageField(message, 'ActualLen')
  92.         call FreeQMessage(session, message)
  93.         message = 0
  94.       end /* (message > 0) */
  95.       else
  96.       do
  97.         say "GetNextQMessage returned NULL... probably because we caught a signal."
  98.       end
  99.     end /* (session > 0) */
  100. end
  101. else say "Couldn't connect to server, sorry."
  102.  
  103.  
  104. /* Our error handling/cleanup routine starts here */
  105. ERROR:
  106. SYNTAX:
  107. HALT:
  108. BREAK_C:
  109.   say "CTRL-C or error detected in line " || sigl
  110.   if (message > 0) then do
  111.     call FreeQMessage(session, message)
  112.     end
  113.   if (session > 0) then do
  114.     call QFreeSession(session)
  115.     end
  116.   exit
  117.  
  118.  
  119. /* Command processsing "subroutine" */
  120. BREAK_F:
  121.   say "CTRL-F detected, now reading user commands from console."
  122.   done = 0
  123.   do while (done = 0)
  124.     say "Enter next command, or just press enter to send all queued commands."
  125.     parse pull cmd args .
  126.     if (length(cmd) = 0) then 
  127.     do
  128.        call QGo(session, 0)
  129.        done = 1
  130.     end
  131.     else 
  132.     do
  133.        /* parse out args if there is an = sign */
  134.        parse var args arg1 '=' arg2
  135.        
  136.        res = -100
  137.        
  138.             if (cmd = 'A') then res=QSetMessageAccessOp(session, arg1) 
  139.        else if (cmd = 'm') then res=QMessageOp(session, arg1, arg2)
  140.        else if (cmd = 'M') then res=QSysMessageOp(session, arg1, arg2)   
  141.        else if (cmd = 'a') then res=QSetAccessOp(session, arg1)          
  142.        else if (cmd = 's') then res=QSetOp(session, arg1, arg2) 
  143.        else if (cmd = 'S') then res=QStreamOp(session, arg1, arg2) 
  144.        else if (cmd = 'r') then res=QRenameOp(session, arg1, arg2)       
  145.        else if (cmd = 'D') then res=QDebugOp(session, arg1)              
  146.        else if (cmd = 'g') then res=QGetOp(session, arg1)            
  147.        else if (cmd = 'd') then res=QDeleteOp(session, arg1)             
  148.        else if (cmd = 'i') then res=QInfoOp(session)                        
  149.        else if (cmd = 'c') then res=QSubscribeOp(session, arg1)      
  150.        else if (cmd = 'C') then res=QGetAndSubscribeOp(session, arg1)
  151.        else if (cmd = 'k') then res=QClearSubscriptionsOp(session,arg1) 
  152.        else if (cmd = 'p') then res=QPingOp(session)                             
  153.        else if (cmd = 'v') then res=QRequestPrivilegesOp(session,arg1)  
  154.        else if (cmd = 'w') then res=QReleasePrivilegesOp(session,arg1)  
  155.        else if (cmd = '!') then res=QKillClientsOp(session,arg1)              
  156.        else if (cmd = '?') then res=QGetParameterOp(session,arg1)             
  157.        else if (cmd = '$') then res=QSetParameterOp(session,arg1,arg2)        
  158.  
  159.        if (res = -100) then say "Unknown command character [" || cmd || "]"
  160.                        else say "Command processed, opCode was " || res
  161.     end
  162.   end
  163.   say "Sending commands and resuming main loop..."
  164.   signal on break_f
  165.   signal MainLoop
  166.